<?php
		// Open database connection
$dbHost = "sid3.comp.nus.edu.sg";
$dbHostPort="1521";
$dbServiceName = "sid3.comp.nus.edu.sg";
$usr = "A0103863";
$pswd = "cs2102std";
$dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$dbHost.")(PORT=".$dbHostPort."))(CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";
$dbConn = oci_connect($usr,$pswd,$dbConnStr);

if(!$dbConn)
{
	$err = oci_error();
	print('Could not establish a database connection: ' . $err['message']);
}
else
{

	// Check so that there is no student with this matriculation number already
	$strSQL = "SELECT * FROM student WHERE matric='".strtoupper($_GET['regmatric'])."'";
	$stmt = oci_parse($dbConn,$strSQL);
	if (!oci_execute($stmt)) {
		$err = oci_error($stmt);
		print('Query failed: '.$err['message']);
	}
	oci_fetch($stmt);
	if (oci_num_rows($stmt) != 0){		
		print "<p>There is already a registered student with this Matriculation Number.</p>";
		print "<a href='index.php'>Go to login page</a>";
	}else{
		// Insert a new student
		$strSQL = "INSERT INTO student (matric, name, email, contact_no, password) VALUES ('".strtoupper($_GET['regmatric'])."','".$_GET['regname']."','".$_GET['regemail']."','".$_GET['regno']."','".$_GET['regpass1']."')";
		$stmt = oci_parse($dbConn,$strSQL);
		if (!oci_execute($stmt)) {
			$err = oci_error($stmt);
			print('Query failed: '.$err['message']);
		}else{
			print "<h1>The registration was successful</h1>";
			print "<a href='index.php'>Go to login page</a>";
		}
	}
}
?>